package server

import (
	"github.com/go-redis/redis"
	"go.uber.org/zap"

	"fiber/config"
	"fiber/global"
)

func InitializeRedis() *redis.Client {
	client := redis.NewClient(&redis.Options{
		Addr:     config.Redis.Host + ":" + config.Redis.Port,
		Password: config.Redis.Password, // no password set
		DB:       config.Redis.DB,       // use default DB
	})
	_, err := client.Ping().Result()
	if err != nil {
		global.Log.Error("Redis connect ping failed, err:", zap.Any("err", err))
		return nil
	}

	global.Redis = client

	return client
}
